/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package sane;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Random;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JToggleButton;
import uk.ac.bath.util.MyRandom;

/**
 *
 * @author pjl
 */
public class Main {

    public static void main(String args[]) {


        Random r = new Random();

        MyRandom.setSeed(r.nextLong());
        Context c = new Context();
        final ProgressViewer view = new ProgressViewer();

        view.view.setPreferredSize(new Dimension(600, 400));

        Population pop = new Population(c, view);


        JFrame frame = new JFrame();
        JPanel panel = new JPanel(new BorderLayout());

        panel.add(view.view,BorderLayout.CENTER);

        JPanel butPanel=new JPanel();

        JButton but = new JButton("RESET");
        but.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                view.reset();
            }
        });

        butPanel.add(but);


        final JToggleButton tbut = new JToggleButton(" MANUAL");
        tbut.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                view.setManual(tbut.isSelected());
            }
        });

        butPanel.add(tbut);


        
        panel.add(butPanel,BorderLayout.SOUTH);

        //    frame.setSize(800, 600);
        frame.setContentPane(panel);
        frame.validate();
        frame.pack();
        frame.setVisible(true);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        while ((!pop.step()) && pop.generation < c.MAX_GENERATIONS) {
        }

    }
}
